<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019\7\15 0015
 * Time: 17:21
 */
//$res=range('1547708168', '1547793445', '86400');
//var_dump($res);
function testMultipleURL(){
    $urls = array(
        'https://979137.com/',
        'https://www.sina.com.cn/',
        'https://www.sohu.com/',
        'https://www.163.com/'
    );
    //1、初始化一个批处理handle
    $mh = curl_multi_init();
    //2、往批处理handle 添加curl_init来的子handle
    foreach ($urls as $i => $url) {
        $conn[$i] = curl_init($url);
        curl_setopt($conn[$i], CURLOPT_HEADER, 0);
        curl_setopt($conn[$i], CURLOPT_CONNECTTIMEOUT, 60);
        curl_setopt($conn[$i], CURLOPT_RETURNTRANSFER, true);
        curl_multi_add_handle($mh, $conn[$i]);
    }
    //3、并发执行，直到全部结束。
    do {
        curl_multi_exec($mh, $active);
    } while ($active);
    //4、获取结果
    foreach ($urls as $i => $url) {
        $data = curl_multi_getcontent($conn[$i]);
       // var_dump($data);
        for ($j=0; $j < 1000; $j++) {
//            echo $j;
//            echo "<br />";
        }
    }
    //5、移除子handle，并close子handle
    foreach ($urls as $i => $url) {
        curl_multi_remove_handle($mh,$conn[$i]);
        curl_close($conn[$i]);
    }
    //6、关闭批处理handle
    curl_multi_close($mh);
}
testMultipleURL()
?>
